<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title>推广端商户列表</title>
    <link href="__PUBLIC__/home/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/home/css/alert.css" rel="stylesheet">
    <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
    <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <link href="__PUBLIC__/home/css/common.css" rel="stylesheet">
</head>

<body>
<div class="container-fluid">
    <!-- Page Heading -->
    <form class="form-inline" method="post" action="{:U('Store/index')}">
        <div class="form-group">
            <label for="exampleInputName2">用户名</label>
            <input type="text" class="form-control" id="exampleInputName2" placeholder="请输入用户名" name="user_name" value="{$info.user_name}">
        </div>
        <div class="form-group">
            <label for="exampleInputEmail2">店铺名称</label>
            <input type="text" class="form-control" id="exampleInputEmail2" placeholder="请输入店铺名称" name="store_name" value="{$info.store_name}">
        </div>
        <button type="submit" class="btn btn-default">查询</button>
        <button type="button" class="btn btn-sm btn-primary btn-add"><span class="glyphicon glyphicon-folder-open"></span>添加</button>

    </form>

    <div class="row">
        <div class="col-lg-12">
            <h2></h2>
            <div class="">
                <table class="table table-bordered table-hover table-striped" id="dataTables-date">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>用户名</th>
                        <th>店铺名</th>
                        <th>店铺性质</th>
                        <th>所在地</th>
                        <th>分享二维码</th>
                        <th>小程序码</th>
                        <th>添加时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="store" id ="sto">
                        <tr>
                            <td>{$sto.serial_number}</td>
                            <td>{$sto.user_name}</td>
                            <td>{$sto.store_name}</td>
                            <td>{$sto.store_type_value}</td>
                            <td>{$sto.region_name}{$sto.address}</td>
                            <td>
                                <a href="javascript:;" class="btn btn-primary qr_code" data-src="{$sto.qr_code}">查看二维码</a>
                            </td>
                            <td>
                                <if condition="$sto['applet_code']">
                                    <a href="javascript:;" class="btn btn-primary applet_code" data-applet_code="{$sto.applet_code}">查看小程序码</a>
                                    <else/>
                                    <a href="javascript:;" class="btn btn-success getApplet_code" data-id="{$sto.store_id}">获取小程序码</a>
                                </if>
                            </td>
                            <td>{$sto.add_time|date="Y-m-d H:i",###}</td>
                            <td><if condition="$sto.state eq 1">已开启<elseif condition="$sto.state eq 2" />已关闭<else />未选择</if></td>
                            <td attr-id="{$sto.store_id}">
                                <button type="button" class="btn btn-default btn-edit" attr-id="{$sto.store_id}">编辑</button>
                                <!--<a href="javascript:;" class="btn btn-primary detail"  data-id="{$sto.store_id}">查看统计详情</a>-->
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- /.row -->
    <div class="pages">
        {$page}
    </div>
</div>
<script src="__PUBLIC__/home/js/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="__PUBLIC__/home/js/bootstrap.min.js"></script>
<script src="__PUBLIC__/home/js/alert.js"></script>
<script src="__PUBLIC__/home/js/layer/layer.js"></script>
<!-- iframe自适应高度 -->
</body>
<script type="text/javascript">
    $(".qr_code").click(function(){
        var src = $(this).attr('data-src');
        if(src){
            var str = "<img style='width:250px;height: 250px;' src="+src+">";
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['auto'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: str
            });
        }else{
            layer.msg('二维码信息错误');
            return false;
        }

    });
    $(".applet_code").click(function(){

        var src = $(this).attr('data-applet_code');
        if(src){
            var str = "<img style='width:250px;height: 250px;' src="+src+">";
            layer.open({
                type: 1,
                title: false,
                closeBtn: 0,
                area: ['auto'],
                skin: 'layui-layer-nobg', //没有背景色
                shadeClose: true,
                content: str
            });
        }else{
            layer.msg('小程序码信息错误');
            return false;
        }
    })

    $(".getApplet_code").click(function(){
        var store_id = $(this).attr('data-id');
        var url = "{:U('Store/getAppletCode')}";
        if(!store_id){
            layer.msg('店铺ID错误');
            return false;
        }
        var index = layer.load(0, {
            shade: false
        }); //0代表加载的风格，支持0-2
        $.post(url,{
            store_id:store_id
        },function(data){
            var res = JSON.parse(data);
            layer.closeAll('loading');
            if(res.code == 1){
                layer.msg(res.msg,function(){
                    window.location.reload();
                })
            }else{
                layer.msg(res.msg);
                return false;
            }
        })

    })

    //查看统计信息
    $(".detail").click(function(){
        var store_id = $(this).attr('data-id');
        var url = "{:U('Store/postData')}";
        $.post(url,{
            store_id:store_id
        },function(data){
            var res = JSON.parse(data);
            if(res.code == 1){
                $.each(res.list,function(index,item){

                })
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['420px', '240px'], //宽高
                    content: 'html内容'
                });
            }else{
                layer.msg('暂无数据');
                return false;
            }
        })
    })

    $("button.btn-add").click(function () {
        location.href = "{:U('Store/insert')}";
    })
    $("button.btn-edit").click(function () {
        location.href = "{:U('Store/revise')}&store_id="+$(this).attr('attr-id');
    })
</script>

</html>
